#ifndef __HEAD__
#define __HEAD__
#include "userTask.h"
#include "threadPool.h"
#define SALT_LEN 12
typedef struct train_s{
    int dataLength;
    char buf[1000];
}train_t;
int tcpInit(char *ip, char *port, int *pSockFd);
int epollAdd(int fd, int epfd);
int epollDel(int fd, int epfd);
//int isUsrLegal(const char* name, const char* password);
void *threadFunc(void *parg);
int makeWorker(threadPool_t *pThreadPool);
int handleEvent(int netFd, char* usr_name, char* curPath);
int recvn(int netFd, void *p, int n);
int download(MYSQL *db, char *argv, int netFd);
int isUsrLegal(const char *usr_name, const char *pwd);
//int cd(char *argv,char *pwd,int netFd);
int cd(MYSQL *db, char *argv, char *pwd, char *usr_name, int netFd);
int ls(MYSQL *db, char *pwd, int netFd);
//int rm(char *argv,char *pwd,int netFd);
int rm(MYSQL *db, char *argv, char *pwd, char *usr_name, int netFd);
int pwd(char *pwd, int netFd);
//int makedir(char *argv,char *pwd,int netFd);
int makedir(MYSQL *db, char *argv,char *pwd, char *usr_name, int netFd);
int removedir(MYSQL *db, char *argv, char* pwd, char* usr_name, int netFd);
int sendfile(char *argv,int sockFd);
// int upload(char* argv, char* pwd, int netFd);
int getSalt(char salt[]);
int getFileName(char *fileName, const char *curPath);

/*sql语句*/
int initDataBase(MYSQL *db);
int usrRegister(MYSQL *db, char* usr_name, char* passwd);
int usrLogin(MYSQL *db, char* usr_name, char* inputPasswd);  //密码错误返回-1， 正确返回0， 用户不存在返回-2
int insertCatalogWhenRegister(MYSQL *db, char *usr_name);
int insertCatalog(MYSQL *db, char *file_name, char *usr_name, int pre_id, char *md5);
int getIdFromFileName(MYSQL *db, char* file_name);
int upload(MYSQL *db, char *argv, char *pwd, char *usr_name, int netFd);
int getMd5FromFileName(MYSQL *db, char *file_name, char *md5);
int insertDirToCatalog(MYSQL *db, char *file_name, char *usr_name, int pre_id);
int findChildFileAndDirFromPreId(MYSQL *db, int preId, char *arr);
int isDirAndIsBlongToUsr(MYSQL *db, char *file_name, char *usr_name);
int FindFatherPathByChildPath(MYSQL *db, char *child_file_name, char *father_file_name);
int delCatalogByFilename(MYSQL *db, char *file_name);
int isFileAndIsBlongToUsr(MYSQL *db, char *file_name, char *usr_name);
int isDirCanDelete(MYSQL *db, char *file_name, char *usr_name);
int delCatalogById(MYSQL *db, int id);
int delDirFromFilename(MYSQL *db, char *file_name);


//第四期

/*建立表格
create table UserLoginInformation(idx int primary key auto_increment, usr_name varchar(255) unique key, salt varchar(30), crypt varchar(255), unique(usr_name));
create table Catalog(id int primary key auto_increment, file_name varchar(255), usr_name varchar(255), pre_id int, md5 varchar(50), unique(file_name));
*/
int makeToken(char* salt, char* usr_name, char* token);

/*新的sql语句*/
int insertTokenToUserInformation(MYSQL *db, char *usr_name, char *token);
int usrRegisterWithToken(MYSQL *db, char* usr_name, char* passwd, char* token);
int findTokenWithUsrName(MYSQL *db, char* usr_name, char* token);
int setTokenNull(MYSQL *db);
int getCommand(char *buf, char *command);
#endif